***** RUN DO_MASTER.do ***** do "$Do\DO_MASTER.do"

global program "OA_TableB11"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.1.1 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property"
global ctrl_plus	"mean_votation lcrSR_F_N"

global fe			"charact_agglo"

// Get sample

qui reghdfe oui endog_mk /// 
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	 

// Get stats
	
estpost tabstat ///
	oui endog_mk instr_dev_mk $ctrl_plus $ctrl_base if e(sample) ///
	, s(N mean sd min max) columns(statistics)
matrix N=e(count)
matrix m=e(mean) // e(Mean) // 
matrix s=e(sd) // e(SD) // 
matrix i=e(min) // e(Min) // 
matrix a=e(max) // e(Max) // 

matrix obs = N'
matrix mean=m'
matrix sd=s'
matrix min=i'
matrix max=a'

matrix b = obs, mean, sd, min, max
matrix list b

// Labels

la var oui		 			"Minaret Ban ''Yes'' Vote (\%)"
la var endog_mk 			"[0.1em] Crime News Exposure ($ \mathtt{CNE} $)"
la var instr_dev_mk 		"[0.1em] HQ Crime Propensity Differential Deviation ($ \mathtt{\Delta HQC} $)"
la var lcrSR_F_N 			"[0.1em] Local Crime Propensity Differential ($ \mathtt{CPD} $)"
la var mean_votation 		"[0.1em] Past Vote Outcomes"
la var sh_lde 				"[0.1em] German-speaking (\%)"
la var lpop_A 				"[0.1em] Log population"
la var sh_prot 				"[0.1em] Protestants (\%)"
la var sh_F 				"[0.1em] Immigrants (\%)"
la var sh_F_new 			"[0.1em] Net Immigration (\%)"
la var sh_cspsup 			"[0.1em] High-skilled (\%)"
la var lmean_reink			"[0.1em] Log Net Income (ChF)"
la var lmean_reink2			"[0.1em] Log Net Income Squared"
la var sh_seco 				"[0.1em] Secondary Employment (\%)"
la var sh_tert 				"[0.1em] Tertiary Employment (\%)"
la var charact_altitude 	"[0.1em] Elevation (km)"
la var charact_altitude_std "[0.1em] Ruggedness"
la var sh_M 				"[0.1em] Muslim (\%)"
la var sh_active 			"[0.1em] Active (\%)"
la var sh_young 			"[0.1em] Young (\%)"
la var mk					"[0.1em] Newspaper Market Shares"
la var com_property			"[0.1em] Local Property Crime"

// Export table

estout matrix(b, fmt(0 2 2 2 2)) using ///
	"$Results\\$program.tex", replace style(tex) type label ///
	unstack collabels(none) ///
	mlabels(, none) ///
	msign(--) ///
	title(News and voting: Summary statistics) ///
	prehead("\begin{table}[!h]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}}" ///
	"\label{$program}"  /// 
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{5}{c}@{}}" ///
	"\hline" "\hline" ///
	"	&\multicolumn{1}{c}{Obs.} &\multicolumn{1}{c}{Mean}  &\multicolumn{1}{c}{Std.Dev.}  &\multicolumn{1}{c}{Min}  &\multicolumn{1}{c}{Max}\\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" ///
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" ///
	"The unit of observation is a municipality. " ///
	"Vote data comes from the Swiss Statistical Office (FSO). " ///
	"News data collected by the authors. " ///
	"Crime data comes from the Swiss Statistical Office (FSO). " ///
	"Newspaper circulation data comes from the Research and Studies in Advertising Media Association (\textit{WEMF/REMP}). " ///
	"Other municipality characteristics data comes from the Swiss Statistical Office (FSO). " ///
	"$ \mathtt{CNE} $ constructed using articles published in from Jan 1, 2009 to Nov 29, 2009. " ///
	"$ \mathtt{\Delta HQC} $, Local Crime Propensity Differential, Local Property Crime constructed using crime data from Jan 1, 2009 to Nov 29, 2009. " ///
	"Newspaper Market Shares constructed for the 2006-2008 period. " ///
	"All other variables are constructed for the year 2009 with the exception of sectoral employment, language, religion, and skills level that are constructed using data from 2000. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
